<?php
	include dirname(dirname(dirname(__FILE__))).'/include/db_connect.php';
	function alertInfo($msg,$url) {
	echo '<!DOCTYPE html><html><head><script>alert("'.$msg.'");
		window.location="'.$url.'";</script></head><body></body></html>';
}

function updateEmployApply($params,$s_user_id){
	$sql = "update s_user set ";
	$tmp = "";
	foreach ($params as $key => $item) {
		$tmp.=",".$key." = ".$item;
	}
	$sql = $sql.substr($tmp, 1).' where id = '.$s_user_id.';';
	$conn = get_db_conn();
	if(mysql_query($sql,$conn)) return true;
	else  return false;


}
function getEmployApply($s_user_id){
	$s_user_id=addslashes($s_user_id);
	$conn=get_db_conn();
	$sql='select * from employ_apply 
	 where s_user_id="'.$s_user_id.'";';
	$result=mysql_query($sql,$conn) or die (mysql_error());
	$ret = mysql_fetch_array($result);
	mysql_close($conn);
	return $ret;	
		
}
	function addEmployApply($params){
	$col="";
	$val="";
	foreach ($params as $key => $item) {
		$col.=",".$key;
		$val.=",".$item;
	}
	$sql = "insert into employ_apply(".substr($col, 1).") values (".substr($val, 1).");";
	$conn = get_db_conn();
	if(mysql_query($sql,$conn))return true;
	else  {
		
		echo mysql_error();
		return false;
	}


	
}	
	function  getUsername($user_id){
		$sql = 'select  username from s_user where id="'.$user_id.'";';
		$conn = get_db_conn();
		$result = mysql_query($sql,$conn) or die("db error");
		$ret = mysql_fetch_array($result);
		if($ret!=null)return $ret["username"];
		else return null;
		
	}
	
	function is_on_work($user_id) {
		$username=getUsername($user_id);
		$sql = 'select count(*) as cnt from user where username="'.$username.'";';
		$conn = get_db_conn();
		$result = mysql_query($sql,$conn) or die("db error");
		$ret = mysql_fetch_array($result);
		if($ret['cnt']>0)return true;
		else return false;
	}
?>